package com.sc.nft.admin.consume;

import com.sc.nft.dao.TradingPoolConfigDao;
import com.sc.nft.dao.TradingPoolOrderDao;
import com.sc.nft.entity.vo.TradingPoolOrderSynchronizationVO;
import com.sc.nft.enums.MessageTopic;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@RocketMQMessageListener(topic = MessageTopic.QUANTITY_AND_PRICE_SYNCHRONIZATION + "${spring.profiles.active}", consumerGroup = MessageTopic.QUANTITY_AND_PRICE_SYNCHRONIZATION + "${spring.profiles.active}")
@Component
@Slf4j
@RequiredArgsConstructor
public class TradingPoolQuantityAndPriceConsumer implements RocketMQListener<Long> {

    private final TradingPoolConfigDao tradingPoolConfigDao;
    private final TradingPoolOrderDao tradingPoolOrderDao;

    @Override
    public void onMessage(Long id) {
        log.info("交易池数量价格同步收到消息:{}", id);
        // 根据id 获取当日订单情况让后同步到对应的交易池配置表中
        TradingPoolOrderSynchronizationVO orderSynchronizationByTradingPoolId = tradingPoolOrderDao.getOrderSynchronizationByTradingPoolId(id);
        tradingPoolConfigDao.updateDealToday(id,orderSynchronizationByTradingPoolId.getTodayHighest(),orderSynchronizationByTradingPoolId.getTodayLowest(),orderSynchronizationByTradingPoolId.getToDayVolume());
    }
}
